<template>
	<view class="tolel">
		
		<!-- <view class="mengbic" v-if="showimg==0" @click="closeFn">
			
		</view>
		<view class="imagw" v-if="showimg==0" @click="tiaozFn">
			<image src="https://shengyue.yaoyunxin.cn/uploads/images/20240127/2024012710535950b6f4917.png" class="img-laba"></image>
		</view> -->
<!-- 		<button open-type="share">
			<image src="../../static/images/sharee.png" class="share" mode=""></image>
			</button> -->
<!-- 		<view class="top">
			<view class="top-top">
				<view class="top-top-left">
					<image class="gs" :src="qiye.qyimg" mode=""></image>
				</view>
				<view class="top-top-right">
					<view class="gs-name">
						{{qiye.qyname}}
					</view>
					<view class="gs-type">
						<view class="" style="width: 144rpx; height: 38rpx;">
							<image style="width: 144rpx; height: 38rpx;" src="../../static/images/qiqi.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<view class="top-bottom">
				{{qiye.qyxaingqing}}
			</view>
		</view> -->
		<view class="top" @click="gotoFn1">
					<view class="top-top">
						<view class="top-top-left">
							<image class="gs" :src="newsData.yonghu.avatar" mode=""></image>
						</view>
						<view class="top-top-right">
							<view class="gs-name">
								{{newsData.yonghu.nickname}}
							</view>
						</view>
					</view>
				</view>
		<view class="goods-detail">
			<view class="goods-detail-top">
				<view class="goods-detail-top-left">
					{{newsData.name}}
				</view>
				<!-- <view class="goods-detail-top-right">
					<view class="km">
						{{newsData.jiage}}
					</view>
				</view> -->
			</view>
			<view class="goods-detail-bottom">
			<!-- 	<view class="goods-detail-bottom-item">
					<view class="left">
						品种规格
					</view>
					<view class="right">
						{{newsData.specifications}}
					</view>
				</view> -->
				<view class="goods-detail-bottom-item">
					<view class="left">
						库存地
					</view>
					<view class="right">
						{{newsData.producer}}
					</view>
				</view>
				<view class="goods-detail-bottom-item">
					<view class="left">
						发布时间
					</view>
					<view class="right">
						{{newsData.fbtime}}
					</view>
				</view>
			</view>
		</view>
		<view class="phone">
			<view class="procure-top">
				<view class="xian">

				</view>
				<view class="procure-top-title">
					联系方式
				</view>
			</view>
			<view class="phone-bottom">
				<view class="phone-bottom-item" v-for="(item,index) in newsData.contacts">
					<view class="phone-bottom-item-top">
						<image style="width: 80rpx; height: 80rpx;" src="../../static/images/toi.png" mode=""></image>
					</view>
					<view class="phone-bottom-item-bottom">
						<view class="people">
							{{item.name}}
						</view>
						<view class="tel">
							{{item.tel}}
						</view>
					</view>
					<view class="zhuzhi">
						<image style="width: 52rpx; height: 52rpx; margin-right: 30rpx;" src="../../static/images/fuzhi.png" mode="" @click="copyFn(item.tel)"></image>
						<image style="width: 52rpx; height: 52rpx;" src="../../static/images/phone.png" mode="" @click="phoneFn(item.tel)"></image>
					</view>
				</view>
			</view>
		</view>
<!-- 		<view class="datail">
			<view class="procure-top">
				<view class="xian">
			
				</view>
				<view class="procure-top-title">
					详情信息
				</view>
			</view>
			<view class="datail-bottom">
				<view class="datail-bottom-item">
					
					<rich-text :nodes="goodsContentConv(newsData.ycxq)"></rich-text>
				</view>
			</view>
		</view> -->
		<view class="procure">
			<view class="procure-top">
				<view class="xian">
		
				</view>
				<view class="procure-top-title">
					详情信息
				</view>
			</view>
			<view class="procure-bottom">
				{{newsData.jjxq}}
				<!-- 党参、北沙参、南沙参、麦冬、白前、泽泻、半夏、苍术、三棱、红景天、沙苑子、蕉丝子、王不留行、覆盆子、地肤子、酸枣仁、佛手、泽兰、金沸草、通草获神、乌梢蛇、蜂房、芒硝、五倍子、薪蛇、金养麦、阳起石、防己、竹茹、斑鸠、蟾酥 -->
			</view>
		</view>
		<view class="datail">
			<view class="procure-top">
				<view class="xian">
			
				</view>
				<view class="procure-top-title">
					<!-- 详情信息图片 -->
					详情信息图片<span style="font-size:26rpx;color: #619ce4;">(点击查看完整图片)</span>
				</view>
			</view>
			<view class="datail-bottom">
				<view class="datail-bottom-item">
					<image v-for="item in newsData.ycxq" :src="item" mode="aspectFill" class="datail-bottom-item-img" @click="yulan(item)"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from 'vue'
	import { useUserStore } from '@/stores/user'
	import { getgongDetails,getqiyeDetail } from '@/api/news'
	import { storeToRefs } from 'pinia'
	import { onShow,onLoad,onShareAppMessage,onShareTimeline  } from '@dcloudio/uni-app'
	const userStore = useUserStore()
	const { userInfo, isLogin } = storeToRefs(userStore)
	const showimg=ref('1')
	let newsId = ''
	let userId=''
	onShow(() => {
		if(!isLogin.value){
			uni.navigateTo({
				url:"/pages/login/login"
			})
		}
		// console.log(userInfo.value);
		

	})
	
	
	let user_id=''
	const gotoFn1=()=>{
		uni.navigateTo({
			url:"/pages/collection/yonghu_detile?userId="+user_id
		})
	}

	const closeFn=()=>{
		showimg.value=1
	}
	const tiaozFn=()=>{
		uni.navigateTo({
			url:'/pages/user/member'
		})
	}

	onLoad((options: any) => {
	    newsId = options.id
		// console.log(userId,'userId');
	    getData(newsId)
		// getqiye()
		userStore.getUser()
		// if(userInfo.value.vip_times=='0'){
		// 	showimg.value='0'
		// }
		// console.log(isLogin.value,'isLogin');
	
	})
	const newsData = ref<any>({})
	const getData = async (id) => {
	    let aa = await getgongDetails({ id })
		newsData.value=aa
		console.log(newsData.value,'newsData.value');
		newsData.value.contacts=JSON.parse(newsData.value.contacts)
		newsData.value.ycxq=JSON.parse(newsData.value.ycxq)
		user_id=newsData.value.yonghu.id
		// newsData.value.ycxq=goodsContentConv(newsData.value.ycxq)
		// clog
		
	}
	const qiye=ref({})
	const getqiye=async()=>{
		qiye.value=await getqiyeDetail({
			user_id:userId
		})
		// console.log(data);
	}
	const gotoFn=()=>{
		uni.navigateTo({
			url:"/pages/collection/enterprise_details?userId="+userId
		})
	}
	const goodsContentConv=(html)=>{
		// console.log(content,'content');
		 // return content.replace(/<(img).*?(\/>|<\/img>)/g, function (mats) {
		 //      if (mats.indexOf('style') < 0) {
		 //        return mats.replace(/<\s*img/, '<img style="max-width:100%;height:auto;"');
		 //      } else {
		 //        return mats.replace(/style=("|')/, 'style=$1max-width:100%;height:auto;')
		 //      }
		 //    });
var GRT = [
					// img 样式
					['img', "max-width:100%;height:auto;"],
				];
				for (let i = 0; i < GRT.length; i++) {
					html = html.replace(new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi'), function(word) {
						// 分析 dom 上是否带有 style=""
						if (word.indexOf('style=') != -1) {
							var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
							return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
						} else {
							var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
							return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
						}
					});
				}
				return html;
	}
	const copyFn=(tel:any)=>{
			// uni.setClipboardData({
			// 				data: tel,
			// 				success: () => {
			// 					uni.showToast({
			// 						title: '复制成功'
			// 					})
			// 				}
			// 			})
		const str = tel;
		const inputo = document.createElement("input");
		document.body.appendChild(inputo);
		inputo.value = str;
		inputo.setAttribute('readOnly', 'readOnly')
		inputo.select();
		document.execCommand("Copy");
		document.body.removeChild(inputo);
		uni.showToast({
								title: '复制成功'
							})
			

	}
	
	const yulan=(item)=>{
			wx.previewImage({
					urls: newsData.value.ycxq, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					current: item, // 当前显示图片的http链接，默认是第一个
					success: function (res) { },
		
				})
	}
	const phoneFn=(tel:any)=>{
		if(userInfo.value.vip_num==0&&userInfo.value.vip_time==0){
			showimg.value='0'
			return false
		}
			let platform = uni.getSystemInfoSync().platform
			switch (platform) {
				case 'android':
					uni.showActionSheet({
					    itemList: [tel,'呼叫'],
					    success:function(res){
							console.log(res);
							if(res.tapIndex==1){
								plus.device.dial(tel,false)        
							}
					    },
					    complete: function(res) {
					       console.log("安卓失败",res)
					    }
					})
					break;
				case 'ios':
					// 使用uni-app提供的借口
					uni.makePhoneCall({
						phoneNumber: tel
		 
					})
					break;
				default:
	}
	}
</script>

<style lang="scss" scoped>
	.procure {
		margin-top: 28rpx;
		// height: 380rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		padding: 20rpx;
	
		.procure-top {
			padding-bottom: 16rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			display: flex;
			padding-bottom: 20rpx;
			border-bottom: 2rpx solid #F5F5F5;
	
			.xian {
				width: 6rpx;
				height: 28rpx;
				background: #19C181;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				opacity: 1;
				margin-top: 11rpx;
				margin-right: 8rpx;
			}
	
		}
	
		.procure-bottom {
			padding: 20rpx;
			background: #F8F8F8;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			opacity: 1;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #777777;
			line-height: 33rpx;
	
		}
	
	}
	
	.mengbic{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0,0,0,0.2);
		z-index: 2;
	}
	.imagw{
		width: 750rpx;
		height: 730rpx;
		position: absolute;
		top: 274rpx;
		left: 50%;
		transform: translate(-50%,0);
		z-index:3;
	}
	.img-laba{
		width: 750rpx;
		height: 730rpx;
	}
	.zhuzhi{
		margin-left: auto;
		margin-top: 10rpx;
	}
	.goods-detail{
		margin-top: 28rpx;
		// height: 380rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		padding: 20rpx;
		
		.goods-detail-top {
			padding-bottom: 16rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			display: flex;
			border-bottom: 2rpx solid #F5F5F5;
			.goods-detail-top-left{
				flex: 1;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
			
			}
			.goods-detail-top-right{
				
				
				.km{
					// width: 148rpx;
					padding: 5rpx 10rpx;
					// height: 44rpx;
					background: #19C280;
					box-shadow: 0rpx 2rpx 17rpx 0rpx rgba(25,194,128,0.37);
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					opacity: 1;
					line-height: 44rpx;
					text-align: center;
					font-size: 26rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				
				}
			}
		
		}
		.goods-detail-bottom{
			.goods-detail-bottom-item{
				margin-top: 20rpx;
				display: flex;
				.left{
					width: 30%;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #333333;
					
				}
				.right{
					flex: 1;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #777777;
				
				}
			}
		}
		
	}
	.share{
		width: 216rpx;
		height: 82rpx;
		position: fixed;
		right: 20rpx;
		bottom:110rpx;
	}
	.datail{
		margin-top: 48rpx;
		margin-bottom: 50rpx;
		padding-bottom: 100rpx;
		.procure-top {
			padding-bottom: 16rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			display: flex;
			border-bottom: 2rpx solid #F5F5F5;
			.xian {
				width: 6rpx;
				height: 28rpx;
				background: #19C181;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				opacity: 1;
				margin-top: 11rpx;
				margin-right: 8rpx;
			}
		
		}
		.datail-bottom{
			padding: 20rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			.datail-bottom-item{
				overflow: hidden;
				padding: 20rpx;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				border: 2rpx solid #F5F5F5;
				text-align: center;
				.datail-bottom-item-img{
					width: 180rpx;
					height: 180rpx;
					margin-right: 3rpx;
				}
			}
		}
	}
	.tolel {
		width: 92%;
		margin-left: 4%;

		.top {
			background-color: #fff;
			height: 170rpx;
			padding: 28rpx;
			margin-top: 28rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;

			.top-top {
				display: flex;

				.top-top-left {
					.gs {
						width: 108rpx;
						height: 108rpx;
					}
				}

				.top-top-right {
					padding-left: 20rpx;
					flex: 1;

					.gs-name {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #333333;
						// margin-bottom: 12rpx;
						line-height: 118rpx;
					}

					.gs-type {
						width: 144rpx;
						height: 38rpx;
						background: rgba(25, 194, 129, 0.05);
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						opacity: 1;
						display: flex;
						justify-content: center;
						line-height: 38rpx;
						font-size: 22rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #19C281;

						.qi {
							display: inline-block;

							.qiye {
								width: 28rpx;
								height: 28rpx;
								vertical-align: middle;
							}
						}

					
					}

				}
			}

			.top-bottom {
				width: 100%;
				height: 66rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #AAAAAA;
				display: -webkit-box;
				/*弹性伸缩盒子模型显示*/
				-webkit-box-orient: vertical;
				/*排列方式*/
				-webkit-line-clamp: 2;
				/*显示文本行数*/
				overflow: hidden;
				/*溢出隐藏*/
			}
		}

		

		.phone {
			margin-top: 28rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 20rpx;

			.procure-top {
				padding-bottom: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				border-bottom: 2rpx solid #F5F5F5;
				.xian {
					width: 6rpx;
					height: 28rpx;
					background: #19C181;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					opacity: 1;
					margin-top: 11rpx;
					margin-right: 8rpx;
				}

			}

			.phone-bottom{
				// margin-top: 20rpx;
				.phone-bottom-item{
					height: 80rpx;
					display: flex;
					margin-top: 20rpx;
					.phone-bottom-item-bottom{
						margin-left: 20rpx;
						.people{
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							color: #333333;
						}
						.tel{
							margin-top: 4rpx;
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #777777;
							
						}
					}
				}
			}
		}
	}
</style>